package cn.vivi.mapper;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import cn.vivi.domain.Classes;
import cn.vivi.util.JDBCUtils;

public class ClassesMapper {

	public QueryRunner runner = JDBCUtils.getQueryRunner();

	public List<Classes> findAll() throws SQLException {
		String sql = "select * from classes";
		return runner.query(sql, new BeanListHandler<Classes>(Classes.class));
	}

	public boolean insert(Classes classes) throws SQLException {
		String sql = "insert into classes values(null, ?, 0)";
		return runner.update(sql, classes.getName()) > 0;
	}

	public boolean delete(String id) throws SQLException {
		String sql = "delete from classes where id = ?";
		return runner.update(sql, id) > 0;
	}

	public boolean update(Classes classes) throws SQLException {
		String sql = "update classes set name = ? where id = ?";
		return runner.update(sql, classes.getName(), classes.getId()) > 0;
	}
}
